package cn.mfk.pethome.dept.service.impl;

import cn.mfk.pethome.base.utils.ResultBean;
import cn.mfk.pethome.dept.domain.Department;
import cn.mfk.pethome.dept.mapper.IDepartmentMapper;
import cn.mfk.pethome.dept.query.DepartmentQuery;
import cn.mfk.pethome.dept.service.IDepartmentService;
import lombok.Data;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private IDepartmentMapper departmentMapper;

    @Override
    public ResultBean<Department> queryAll(DepartmentQuery query) {
        ResultBean resultBean = new ResultBean();
        resultBean.setPageList(departmentMapper.findAll(query));
        resultBean.setTotal(departmentMapper.findCountAll(query));
        return resultBean;
    }

    @Override
    public Department findOne(Long id) {
        return departmentMapper.findOne(id);
    }

    @Transactional
    @Override
    public void addDept(Department department) {
        departmentMapper.addDept(department);
    }
    @Transactional
    @Override
    public void upDept(Department department) {
        departmentMapper.upDept(department);
    }
    @Transactional
    @Override
    public void delDept(Long id) {
        departmentMapper.delDept(id);
    }
}
